<template>
  <div class="subject">
    <span>{{ num1 }}</span>
    <span>+</span>
    <span>{{ num2 }}</span>
    <span>=</span>
    <input v-model="res" :disabled="isDone" type="number" />
    <button @click="fn(index)" :disabled="isDone">提交</button>
  </div>
</template>

<script>
export default {
  props: ["index"],
  data() {
    return {
      num1: parseInt(Math.random() * (20 - 1 + 1) + 1, 10),
      num2: parseInt(Math.random() * (20 - 1 + 1) + 1, 10),
      res: null,
      isDone: false, //禁用状态
    };
  },
  methods: {
    fn() {
      this.isDone = true;
      let resstr = this.num1 + this.num2 == this.res ? "正确" : "错误";
      this.$emit("resfn", resstr, this.index);
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>